////////////////////////////////////////////////
// DESCRIPTION:
//     Class implementationn for device driver
//     context management for stream drivers
//
// Legal Notices:
//     Copyright (c) 2008, Telliam Consulting, LLC.
//     All rights reserved.
//
//     Redistribution and use in source and binary forms, with or without modification,
//     are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright notice,
//       this list of conditions and the following disclaimer in the documentation
//       and/or other materials provided with the distribution.
//
//     * Neither the name of Telliam Consulting nor the names of its contributors
//       may be used to endorse or promote products derived from this software
//       without specific prior written permission.
//
// Disclaimer:
//     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//     IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
//     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
//     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
//     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
//     OF THE POSSIBILITY OF SUCH DAMAGE.  
//
#include <Windows.h>
#include <FusionWare\Win32.h>
#include <FusionWare\DFX\StreamAPI.h>

using namespace FusionWare::DFX;
using namespace FusionWare::Win32;

void IDriverContextImpl::PowerUp()
{
} 

void IDriverContextImpl::PowerDown()
{
}

bool IDriverContextImpl::PreDeinit()
{
    return true;
}

void IDriverContextImpl::Deinit()
{
}

bool IDriverContextImpl::IoControl(DWORD dwCode, BYTE* pInBuf, DWORD InBufSize, BYTE* pOutBuf, DWORD OutBufSize,DWORD* pdwActualOut, bool* pRetVal)
{
	// start out assuming it's a known code that fails
    bool isKnown = true;
    *pRetVal=false;

    if(pdwActualOut)
        *pdwActualOut = 0;

    switch(dwCode)
    {
	case IOCTL_POWER_CAPABILITIES:
        if((pInBuf!=NULL && sizeof(POWER_RELATIONSHIP) > InBufSize) 
            || sizeof(POWER_CAPABILITIES) > OutBufSize)
            break;
        
		*pRetVal = QueryPowerCapabilities((POWER_RELATIONSHIP*)pInBuf, (POWER_CAPABILITIES*)pOutBuf);
        *pdwActualOut = sizeof(POWER_CAPABILITIES);
        break;
    
    case IOCTL_POWER_GET:
        if((pInBuf!=NULL && sizeof(POWER_RELATIONSHIP) > InBufSize)
            || sizeof(CEDEVICE_POWER_STATE) > OutBufSize)
            break;
        
        *pRetVal = QueryPowerState((POWER_RELATIONSHIP*)pInBuf, (CEDEVICE_POWER_STATE*)pOutBuf);
        *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
        break;

	case IOCTL_POWER_QUERY:
        if((pInBuf!=NULL && sizeof(POWER_RELATIONSHIP) > InBufSize)
            || sizeof(CEDEVICE_POWER_STATE) > OutBufSize)
            break;
        
        *pRetVal = QueryPowerStateChange((POWER_RELATIONSHIP*)pInBuf, (CEDEVICE_POWER_STATE*)pOutBuf);
        *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
        break;

	case IOCTL_POWER_SET:
        if((pInBuf!=NULL && sizeof(POWER_RELATIONSHIP) > InBufSize)
            || sizeof(CEDEVICE_POWER_STATE) > OutBufSize)
            break;
        
        *pRetVal = SetPowerState((POWER_RELATIONSHIP*)pInBuf, (CEDEVICE_POWER_STATE*)pOutBuf);
        *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
        break;
	
	case IOCTL_REGISTER_POWER_RELATIONSHIP:
		*pRetVal = RegisterPowerRelationships();
		break;

    default:
	    isKnown = false;
		break;
    }

    return isKnown;
}

bool IDriverContextImpl::QueryPowerCapabilities(const POWER_RELATIONSHIP* pRelationship, POWER_CAPABILITIES* pCaps)
{
	SetLastError(ERROR_NOT_SUPPORTED);
	return false;
}

bool IDriverContextImpl::QueryPowerState(const POWER_RELATIONSHIP* pRelationship, CEDEVICE_POWER_STATE* pState)
{
	SetLastError(ERROR_NOT_SUPPORTED);
	return false;
}

bool IDriverContextImpl::QueryPowerStateChange(const POWER_RELATIONSHIP* pRelationship, CEDEVICE_POWER_STATE* pState)
{
	SetLastError(ERROR_NOT_SUPPORTED);
	return false;
}

bool IDriverContextImpl::SetPowerState(const POWER_RELATIONSHIP* pRelationship, CEDEVICE_POWER_STATE* pState)
{
	SetLastError(ERROR_NOT_SUPPORTED);
	return false;
}

bool IDriverContextImpl::RegisterPowerRelationships()
{
	SetLastError(ERROR_NOT_SUPPORTED);
	return false;
}
